#include <stdio.h>
#include <stdlib.h>

#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>

#define NUM 16

int main(int argc,char* argv[],char* env[])
{

    // 创建子进程用于进行程序替换，父进程用于等待子进程
    pid_t id=fork();

    if(id==0)
    {
      //  char* const _argv[NUM]={
      //      (char*)"ls",
      //      (char*)"-l",
      //      (char*)"-a",
      //      (char*)"-i",
      //      NULL
      //  };  

        char* const _argv[NUM]={
            (char*)"java",
            (char*)"TestDemo",
            NULL 
        };

        char* const _env[NUM]={
            (char*)"-l",
            (char*)"-l",
            NULL
        };

        // int execl(const char *path, const char *arg, ...); 
        //execl("/usr/bin/ls","ls","-l","-a","-i",NULL);
        // int execv(const char *path, char *const argv[]);
        //execv("/usr/bin/ls",_argv);
        // int execlp(const char *file, const char *arg, ...);
        //execlp("ls","ls","-l","-a","-i",NULL);
        // int execvp(const char *file, char *const argv[]);
        //execvp("ls",_argv);
        // int execle(const char *path, const char *arg, ... , char * const envp[]);
        //execle("/home/yx/code-under-linux/three20220922/test","./test",NULL,_env);
        // int execvpe(const char *file, char *const argv[],char *const envp[]);
        //execvpe("/home/yx/code-under-linux/three20220922/test",_argv,_env);
        // int execve(const char *filename, char *const argv[],char *const envp[]);
        execve("/usr/jdk1.8.0_131/bin/java",_argv,_env);
    }
    else 
    {
        int status =0;

        pid_t ret=waitpid(id,&status,0);

        if(ret>0)
        {
            printf("等待成功 退出码：%d 退出信号：%d\n",WEXITSTATUS(status),status&0x7F);
        }

    }
    return 0;
}

